home *** CD-ROM | disk | FTP | other *** search
/ Pascal Super Library / Pascal Super Library (CW International)(1997).bin / TURB_VIS / TVSPY / TVSPY.PAS < prev   
Pascal/Delphi Source File  |  1990-12-17  |  5KB  |  164 lines

  1. program TVSpy;
  2. {$X+}
  3.  
  4. { This program shows TVision events in a special scrolling TEventWindow as the
  5.   events are generated by the user and the application.
  6.  
  7.   All keyboard and mouse events will be displayed by TEventWindow.  All
  8.   broadcast and command events created with PutEvent should be displayed.
  9.   Message events can be intercepted if you include EventWin AFTER the Views
  10.   unit in the uses statements of your source code.  (TVision internal
  11.   messages cannot be intercepted)
  12.  
  13.   While the TEventWindow is deselected, it will capture and display events in
  14.   its scrolling interior.  When TEventWindow is selected, the display of
  15.   events pauses, and you may scroll back through the last 100 events that
  16.   were captured.
  17.  
  18.   THeapWin is a small window that displays the amount of free memory while
  19.   that displays the amount of free memory while the application runs.
  20.  
  21.   TEventWindow is a TTextWindow object with a DisplayEvent method to accept
  22.   a TEvent record and do its best to decipher the event codes.  Insert your
  23.   own event constants and text strings using the InsertCommand method to make
  24.   watching your applications more enjoyable and informative.
  25.  
  26.   A TTextWindow is a TWindow with a TCollection of strings, which are
  27.   displayed by a scrolling interior view (basically).
  28.  
  29.   This application has a do-nothing menubar installed so you can see command
  30.   events at work.  To install a TEventWindow in your own existing application,
  31.   simply init the EventWindow global pointer in your MyApp.Init and insert
  32.   EventWindow^.DisplayEvent(E) in your MyApp.GetEvent.  If your app doesn't
  33.   already override its inherited GetEvent, then use the one in this program.
  34.   Don't forget to call your ancestor's GetEvent!!!!
  35.  
  36.   If you should ever want to close the TEventWindow, don't forget to set the
  37.   global pointer EventWindow to nil, so that dependent routines will know
  38.   not to use it.  (Dispose doesn't set pointers to nil).
  39.  
  40.   New!  Filter option on the EventWindow mini-menu lets you turn off logging
  41.   of different types of events.  Handy when all you want to see are command
  42.   events but you're drowning in mouse move events.
  43.  
  44.   New!  Informative text for keyboard events!  KeyNamer unit returns a text
  45.   string for all the predefined TVision kbxxxx constants.
  46.  
  47.   Enjoy!
  48.  
  49.   Copyright (c) 1990 by Danny Thorpe
  50.  
  51.  
  52.   This program may be freely distributed so long as no fee (other than
  53.   media cost or BBS time charges) is charged and no changes are made to
  54.   this file or its related source units.
  55. }
  56.  
  57.  
  58. uses dos, objects, drivers, menus, views, app, heapwin, eventwin;
  59.  
  60.  
  61. const cmNewWin = 500;
  62.       cmFileOpen = 501;
  63.  
  64.  
  65. type  PMyApp = ^TMyApp;
  66.       TMyApp = object(TApplication)
  67.         constructor Init;
  68.         procedure   GetEvent(var E: TEvent);  virtual;
  69.         procedure   Idle;            virtual;
  70.         procedure   InitStatusLine;  virtual;
  71.         procedure   InitMenuBar;     virtual;
  72.         end;
  73.  
  74. var MyApp: TMyApp;
  75.  
  76.  
  77.  
  78. constructor TMyApp.Init;
  79.   var R:TRect;
  80.   begin
  81.   TApplication.Init;
  82.                                         { retain last 100 lines in scroller }
  83.   Desktop^.GetExtent(R);
  84.   R.Assign(R.A.X,R.B.Y-10,R.B.X div 2,R.B.Y);                       { vvv }
  85.   EventWindow:= new(PEventWindow, Init(R, 'Event Window', wnNoNumber, 100));
  86.   Desktop^.Insert(EventWindow);
  87.  
  88.   EventWindow^.InsertCommand( cmNewWin, 'cmNewWin');
  89.   EventWindow^.InsertCommand( cmFileOpen, 'cmFileOpen');
  90.  
  91.  
  92.   HeapWindow:= new(PHeapWin, Init);
  93.   Desktop^.Insert( HeapWindow);
  94.  
  95.   R.Assign(3,2,60,10);
  96.   Desktop^.Insert(new(PWindow, Init(R, 'Dummy window', wnNoNumber)));
  97.   end;
  98.  
  99.  
  100. procedure TMyApp.GetEvent(var E: TEvent);
  101.   begin
  102.   TApplication.GetEvent(E);
  103.   EventWindow^.DisplayEvent(E);
  104.   end;
  105.  
  106.  
  107. procedure TMyApp.Idle;
  108.   begin
  109.   TApplication.Idle;
  110.   if HeapWindow <> nil then
  111.     HeapWindow^.Update;
  112.   end;
  113.  
  114.  
  115. procedure TMyApp.InitStatusLine;
  116.   var R: TRect;
  117.  
  118.   begin
  119.   GetExtent(R);      { find out how big the current view is }
  120.   R.A.Y := R.B.Y-1;  { squeeze R down to one line at bottom of frame }
  121.   StatusLine := New(PStatusline, Init(R,
  122.                   NewStatusDef(0, $FFFF,
  123.                     NewStatusKey('~Alt-X~ Exit', kbAltX, cmQuit,
  124.                     NewStatusKey('~F4~ New', kbF4, cmNewWin,
  125.                     NewStatusKey('~Alt-F3~ Close', kbAltF3, cmClose,
  126.                     NewStatusKey('',kbF10, cmMenu,
  127.                     nil)))),
  128.                   nil)
  129.                 ));
  130.   end;
  131.  
  132.  
  133.  
  134.  
  135. procedure TMyApp.InitMenuBar;
  136.   var R: TRect;
  137.  
  138.   begin
  139.   GetExtent(R);
  140.   r.b.y:= r.a.y+1;
  141.   Menubar := New(PMenuBar, Init(R, NewMenu(
  142.                NewSubMenu('~F~ile', hcNoContext, NewMenu(
  143.                  NewItem('~O~pen','F3', kbF3, cmFileOpen, hcNoContext,
  144.                  NewItem('~N~ew','F4', kbF4, cmNewWin, hcNoContext,
  145.                  NewLine(
  146.                  NewItem('E~x~it','Alt-X', kbAltX, cmQuit, hcNoContext,
  147.                  nil))))),
  148.                NewSubMenu('~W~indow', hcNoContext, NewMenu(
  149.                  NewItem('~N~ext','F6', kbF6, cmNext, hcNoContext,
  150.                  NewItem('~Z~oom','F7', kbF7, cmZoom, hcNoContext,
  151.                  nil))),
  152.                nil))    { one ) for each menu defined }
  153.              )));
  154.   end;
  155.  
  156.  
  157.  
  158.  
  159.  
  160. begin
  161. MyApp.Init;
  162. MyApp.Run;
  163. MyApp.Done;
  164. end.